package com.heu.blood.recycle.controller;

import com.heu.blood.common.aop.ControllerLogAnnotation;
import com.heu.blood.common.utils.PageUtils;
import com.heu.blood.common.utils.R;
import com.heu.blood.recycle.entity.BloodReturnEntity;
import com.heu.blood.recycle.service.BloodReturnService;
import com.heu.blood.recycle.vo.BloodReturnApplicationVo;
import com.heu.blood.recycle.vo.BloodReturnEntityVo;
import com.heu.blood.recycle.vo.BloodReturnWithExamineVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;




/**
 * 
 *
 * @author ysl
 * @email 
 * @date 2023-08-28 10:20:28
 */
@RestController
@RequestMapping("recycle/bloodreturn")
public class BloodReturnController {
    @Autowired
    private BloodReturnService bloodReturnService;


    /**
     * 分页查询退血信息
     * @param params
     * @return
     */
    @RequestMapping("/list")
    @ControllerLogAnnotation(module = "退血", operate = "分页查询退血信息")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = bloodReturnService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @ControllerLogAnnotation(module = "退血", operate = "根据id查询退血信息")
    public R info(@PathVariable("id") Long id){
		BloodReturnEntityVo bloodReturnEntityVo = bloodReturnService.getById(id);

        return R.ok().put("bloodReturn", bloodReturnEntityVo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @ControllerLogAnnotation(module = "退血", operate = "保存一条退血申请信息")
    public R save(@RequestBody BloodReturnEntity bloodReturn){
		bloodReturnService.save(bloodReturn);

        return R.ok();
    }

    /**
     * 增加一条退血申请信息
     * @param bloodReturn
     * @return
     */
    @RequestMapping("/savebloodreturn")
    @ControllerLogAnnotation(module = "退血", operate = "增加一条退血申请信息")
    public R saveBloodReturn(@RequestBody BloodReturnWithExamineVo bloodReturn){

        return bloodReturnService.saveBloodReturn(bloodReturn) ? R.ok() : R.ok("保存失败");
    }

    /**
     * 退血申请同意
     * @param
     * @return
     */
    @RequestMapping("/approve")
    @ControllerLogAnnotation(module = "退血", operate = "退血申请同意")
    public R approve(@RequestBody BloodReturnEntity bloodReturn){

        return bloodReturnService.approve(bloodReturn) ? R.ok() : R.ok("失败");
    }

    /**
     * 退血申请拒绝
     * @param bloodReturn
     * @return
     */
    @RequestMapping("/reject")
    @ControllerLogAnnotation(module = "退血", operate = "退血申请同意")
    public R reject(@RequestBody BloodReturnEntity bloodReturn){

        return bloodReturnService.reject(bloodReturn) ? R.ok() : R.ok("失败");
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @ControllerLogAnnotation(module = "退血", operate = "修改退血申请信息")
    public R update(@RequestBody BloodReturnEntity bloodReturn){
		bloodReturnService.updateById(bloodReturn);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @ControllerLogAnnotation(module = "退血", operate = "批量删除退血信息")
    public R delete(@RequestBody Long[] ids){
		bloodReturnService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    @RequestMapping("/getReturnAlllicationInformation")
    @ControllerLogAnnotation(module = "退血", operate = "根据血液id查询退血申请单其他信息")
    public R getReturnAlllicationInformation(@RequestParam String bloodId){
        BloodReturnApplicationVo vo=bloodReturnService.getReturnAlllicationInformation(bloodId);
        return R.ok().put("data",vo);
    }

}
